/*
 * @Author: your name
 * @Date: 2021-04-14 20:38:26
 * @LastEditTime: 2021-04-16 16:25:22
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /flutter_demo/lib/pages/TabControl.dart
 */
import 'package:flutter/material.dart';

class TabControlPage extends StatefulWidget {
  @override
  _TabControlPageState createState() => _TabControlPageState();
}

class _TabControlPageState extends State<TabControlPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = new TabController(length: 2, vsync: this);
    _tabController.addListener(() {
      print(_tabController.index);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('tab control'),
        bottom: TabBar(
          controller: this._tabController,
          tabs: <Widget>[
            Tab(text: '热销'),
            Tab(text: '推荐'),
          ],
        ),
      ),
      body: TabBarView(
        controller: this._tabController,
        children: <Widget>[
          Center(
            child: Text('热销'),
          ),
          Center(
            child: Text('推荐'),
          ),
        ],
      ),
    );
  }
}
